<template>
  <div class="my_div">
    <img src="../assets/狗子.jpg" alt="" />
    <p @click="bianse" :style="{ backgroundColor: colorStr }">
      我一条狗，吃饭旅行，走走停停
    </p>
  </div>
</template>

<script>
export default {
  data() {
    return {
      colorStr: "",
    };
  },
  methods: {
    bianse() {
      this.colorStr = `rgb(${Math.floor(Math.random() * 256)}, ${Math.floor(
        Math.random() * 256
      )}, ${Math.floor(Math.random() * 256)})`;
    },
  },
};
</script>

<style>
.my_div {
  width: 300px;
  border: 1px solid black;
  text-align: center;
  float: left;
}

.my_div img {
  width: 100%;
  height: 200px;
}
</style>